// 最长等差数列
class Solution {
    public:
        int longestArithSeqLength(vector<int>& nums) {
            int n = nums.size();
            if(n <= 2) return n;
            unordered_map<int,int> hash;
            hash[nums[0]] = 0;
            vector<vector<int>>dp(n,vector(n,2));
            int ret = 0;
            for(int i = 1; i < n-1; i++)
            {
                for(int j = i + 1; j < n; j++)
                {
                    int a = 2*nums[i]-nums[j];
                    if(hash.count(a))   
                        dp[i][j] = dp[hash[a]][i] + 1;
                    ret = max(ret,dp[i][j]);
                }
                hash[nums[i]] = i;
            }
            return ret ;
        }
    };